package com.whitedust.top90;

/**
 *
 * @author A
 * @since 2025/11/16 21:04
 */

public class Top88 {
    public int maxProduct(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        int[][] dp = new int[nums.length][2];
        if (nums[0] > 0) {
            dp[0][0] = nums[0];
            dp[0][1] = 0;
        } else {
            dp[0][0] = 0;
            dp[0][1] = nums[0];
        }
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > 0) {
                dp[i][0] = Math.max(dp[i - 1][0] * nums[i], nums[i]);
                dp[i][1] = Math.min(dp[i - 1][1] * nums[i], 0);
            } else {
                dp[i][0] = Math.max(dp[i - 1][1] * nums[i], 0);
                dp[i][1] = Math.min(dp[i - 1][0] * nums[i], nums[i]);
            }
            res = Math.max(res, dp[i][0]);
        }
        return res;
    }
}
